package com.example.gzysmartcity.ui.fragment.travel;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.example.gzysmartcity.R;
import com.example.gzysmartcity.databinding.FragmentTravelitemBinding;
import com.example.gzysmartcity.repository.model.SCTravel;
import com.example.gzysmartcity.ui.adapter.BrAdapter;
import com.example.gzysmartcity.ui.adapter.BrStringAdapter;
import com.example.gzysmartcity.ui.base.BaseFragment;
import com.example.gzysmartcity.viewmodel.TravelViewModel;
import com.youth.banner.Banner;
import com.youth.banner.indicator.CircleIndicator;

import org.jetbrains.annotations.NotNull;

public class TravelItemFragment extends BaseFragment<FragmentTravelitemBinding> {
    @Override
    protected FragmentTravelitemBinding viewBinding() {
        return FragmentTravelitemBinding.inflate(getLayoutInflater(), baseBinding.getRoot(), true);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        Bundle arguments = getArguments();
        if (arguments == null) {
            ToastUtils.showShort("获取数据失败");
            remove();
            return;
        }
        TravelViewModel travelViewModel = new ViewModelProvider(requireActivity()).get(TravelViewModel.class);
        SCTravel.DataBean dataBean = (SCTravel.DataBean) arguments.getSerializable("data");
        baseBinding.title.setText(dataBean.getName());
        b.webtra.loadData(travelViewModel.getJourney(dataBean.getId()), "text/html", "utf-8");
//        b.webtra.loadData(dataBean.getContent(), "text/html", "utf-8");
        b.tvTravelItemNum.setText(dataBean.getNum() + "人跟团");
        b.tvTarvelitemTitile.setText("\t\t"+dataBean.getName());
        Banner<String, BrStringAdapter> banner = b.getRoot().findViewById(R.id.banner_travelitem);
        banner.setAdapter(new BrStringAdapter(arguments.getStringArrayList("img")))
                .addBannerLifecycleObserver(this)
                .setLoopTime(2000)
                .setIndicator(new CircleIndicator(getContext()));
        b.tvTravelItemContent.setText("往返交通：\t航班时间可选 \n" +
                "住宿：\t2晚高档酒店\n" +
                "购物：\t无购物\n" +
                "景点：\n" +
                "餐食：\t成人含2早餐2午餐1晚餐, 1次自理，\n" +
                "\t\t\t\t\t儿童含2早餐2午餐1晚餐, 1次自理");
    }

    @Override
    protected String setTitle() {
        return "";
    }

    @Override
    protected boolean showBack() {
        return true;
    }

    @Override
    protected Boolean showBottom() {
        return false;
    }
}
